home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 051-075 / scopedisk70 / magus110 / mprintit.rexx < prev    next >
OS/2 REXX Batch file  |  1995-03-19  |  7KB  |  248 lines

  1. /*---------------------------- Start REXX Source ----------------------------*/
  2.  
  3. /*     MPrintIt.rexx           Revised 15-APR-89
  4.  
  5.     Magus! Print Spooler
  6.            v1.10               Associated files: Magus!.rexx
  7.                                                  Magus!Cntl.rexx
  8.             by                                   Magus!Util.rexx
  9.         Dan Schenck                              MPrint.rexx
  10.          Tulsa, OK
  11.  
  12.       GEnie: D.SCHENCK
  13.        (918) 492-0523
  14.                          */
  15.  
  16. /*  Requires rexxarplib.library v2.1 */
  17.  
  18. parse arg head_pointer cc
  19.  
  20. active_trigger = GetEnv('update_time')
  21. interrupt = 'NOTE---> PRINT PROCESS INTERRUPTED'
  22. schar = '\f'
  23. rchar = '0C'X
  24. call look4spec_char
  25. schar = '\n'
  26. rchar = '0A'X
  27. call look4spec_char
  28. rtn = Setenv('printit_pgm','ACTIVE')
  29.  
  30. do forever
  31.   rtn = Setenv('current_print',head_pointer)
  32.   rtn = Setenv('%_read',0)
  33.   do while(Getenv('prnt_spooler') = 'GETTINGCLIP')
  34.     call delay(25)
  35.   end
  36.   rtn = Setenv('prnt_spooler','GETTINGCLIP')
  37.   instring = Getenv(head_pointer)
  38.   rtn = Setenv('prnt_spooler','NA')
  39.   parse VAR instring fwrd_pointer ' ' file2print ' ' orig_file ' ' copies ' ' lpp ' ' p_no ' ' date ' ' time ' ' file
  40.   orig_file = translate(orig_file," ","^")
  41.   file2print = translate(file2print," ","^")
  42.   call printit
  43.   do while(Getenv('prnt_spooler') = 'GETTINGCLIP')
  44.     call delay(25)
  45.   end
  46.   rtn = Setenv('prnt_spooler','GETTINGCLIP')
  47.   instring = Getenv(head_pointer)
  48.   parse VAR instring fwrd_pointer ' ' rest
  49.   rtn = Setenv(head_pointer,'null')
  50.   if fwrd_pointer = 'null' then
  51.     do
  52.       rtn = Setenv('printit_pgm','NA')
  53.       rtn = Setenv('current_print','null')
  54.       rtn = Setenv('spool_tail','null')
  55.       rtn = Setenv('prnt_spooler','NA')
  56.       address "MAGUSPORT" "DONE"
  57.       exit
  58.     end
  59.   rtn = Setenv('prnt_spooler','NA')
  60.   head_pointer = fwrd_pointer
  61. end
  62.  
  63. printit: procedure expose file2print orig_file cc copies lpp p_no date time file active_trigger interrupt
  64.  
  65.   if ~exists(file2print) then
  66.     do
  67.       say '"' || file2print || '" Does Not Exist"'
  68.       return
  69.     end
  70.   total_bytes = copies * word(statef(file2print),2)
  71.   bytes_read = 0
  72.   if lpp ~= 'null' then
  73.     do
  74.       count_lines = 1
  75.       if (p_no ~= 'null') & (substr(p_no,1,1) = 'b') then lpp = lpp - 2
  76.       else nop
  77.     end
  78.   else count_lines = 0
  79.   dt_string = ""
  80.   file_string = ""
  81.   if upper(date) = 'ON' then dt_string = 'Date: ' || date() || '     '
  82.   if upper(time) = 'ON' then dt_string = dt_string || 'Time: ' || time()
  83.   if upper(file) = 'ON' then file_string = 'File: ' || orig_file
  84.   do i = 1 to copies
  85.     call time('Reset')
  86.     t0 = 0
  87.     total_lines = 0
  88.     count = 0
  89.     page = -1
  90.     do while(~open('out','PRT:','Write'))
  91.       call delay(300)
  92.     end
  93.     if count_lines then
  94.       do
  95.         call new_page
  96.         call page_minder(cc)
  97.         if dt_string ~= "" then call page_minder(dt_string)
  98.         else nop
  99.         if file_string ~= "" then call page_minder(file_string)
  100.         else nop
  101.         call page_minder(' ')
  102.       end
  103.     else
  104.       do
  105.         call writeln('out',cc)
  106.         if dt_string ~= "" then call writeln('out',dt_string)
  107.         if file_string ~= "" then call writeln('out',file_string)
  108.         call writeln('out',' ')
  109.       end
  110.     call open('pfile',file2print,'Read')
  111.     total_rcds = 0
  112.     rec_chk = 10
  113.     do while(~eof('pfile'))
  114.       if Getenv('printit_pgm') = 'ABORT' then
  115.         do
  116.           call close('pfile')
  117.           if count_lines then call page_minder(interrupt)
  118.           else call writeln('out',interrupt)
  119.           call close('out')
  120.           if (index(upper(file2print),"++M!SPOOL/++") > 0) then
  121.             address command 'delete' file2print || " Quiet"
  122.           rtn = Setenv('printit_pgm','ACTIVE')
  123.           return
  124.         end
  125.       instring = readln('pfile')
  126.       bytes_read = bytes_read + length(instring)
  127.       total_rcds = total_rcds + 1
  128.       if total_rcds = rec_chk then
  129.         do
  130.           rec_chk = rec_chk + 10
  131.           rtn = Setenv('%_read',(bytes_read/total_bytes*100))
  132.           if time('E')-t0 > active_trigger then
  133.             do
  134.               address MAGUSPORT "UPDATE"
  135.               t0 = time('E')
  136.             end
  137.         end
  138.       if count_lines then
  139.         do
  140.           if right(instring,1) = '0C'X then
  141.             do
  142.               if count >= lpp then call new_page
  143.               else nop
  144.               call writeln('out',left(instring,length(instring)-1))
  145.               total_lines = total_lines + 1
  146.               call new_page
  147.             end
  148.           else
  149.             do
  150.               if count >= lpp then call new_page
  151.               else nop
  152.               call writeln('out',instring)
  153.               count = count + 1
  154.               total_lines = total_lines + 1
  155.             end
  156.         end
  157.       else call writeln('out',instring)
  158.     end
  159.     if count_lines then
  160.       do
  161.         call page_minder('0A'X || 'Total records in file = ' || total_rcds || '   Total lines printed = ' || total_lines+2 || '   Seconds to print = ' || time('E'))
  162.         if (count > 0) & (substr(p_no,1,1) = 'b') then call new_page
  163.       end
  164.     else call writeln('out','Total records in file = ' || total_rcds || '   Seconds to print = ' || time('E'))
  165.     call close('pfile')
  166.     call close('out')
  167.     call delay(50)
  168.     if (index(upper(file2print),"++M!SPOOL/++") > 0) then
  169.       address command 'delete' file2print || " Quiet"
  170.   end
  171.   return
  172.  
  173. look4spec_char: procedure expose cc schar rchar
  174.  
  175.   spec_char = index(cc,schar)
  176.   do while(spec_char > 0)
  177.     if (spec_char + 2) > length(cc) then cc_rest = ""
  178.     else cc_rest = substr(cc,spec_char+2)
  179.     if spec_char = 1 then cc = ""
  180.     else cc = substr(cc,1,spec_char-1)
  181.     cc = cc || rchar || cc_rest
  182.     spec_char = index(cc,schar)
  183.   end
  184.   return
  185.  
  186. page_minder: procedure expose count lpp total_lines p_no page
  187.  
  188.   parse arg instring
  189.  
  190.   if right(instring,1) = '0C'X then
  191.     do
  192.       if count >= lpp then call new_page
  193.       call writeln('out',left(instring,length(instring)-1))
  194.       total_lines = total_lines + 1
  195.       call new_page
  196.       return
  197.     end
  198.   if count >= lpp then call new_page
  199.   call writeln('out',instring)
  200.   count = count + 1
  201.   total_lines = total_lines + 1
  202.   return
  203.  
  204. new_page: procedure expose count p_no page total_lines
  205.  
  206.   ff = '0C'X
  207.   if p_no ~= 'null' then
  208.     do
  209.       page = page + 1
  210.       t_or_b = substr(p_no,1,1)
  211.       if page = 0 then
  212.         if t_or_b = 'b' then
  213.           do
  214.             call writech('out',ff)
  215.             return
  216.           end
  217.         else page = 1
  218.       else nop
  219.       total_lines = total_lines + 2
  220.       if t_or_b = 't' then call writech('out',ff)
  221.       else call writeln('out',' ')
  222.       where = substr(p_no,2,1)
  223.       page_text = 'Page ' || page
  224.       select
  225.         when where = 'l' then call writeln('out',page_text)
  226.         when where = 'c' then call writeln('out',center(page_text,80))
  227.         when where = 'r' then call writeln('out',copies(' ',80-length(page_text)) || page_text)
  228.       end
  229.       if t_or_b = 't' then
  230.         do
  231.           count = 2
  232.           call writeln('out',' ')
  233.         end
  234.       else
  235.         do
  236.           count = 0
  237.           call writech('out',ff)
  238.         end
  239.     end
  240.   else
  241.    do
  242.      call writech('out',ff)
  243.      count = 0
  244.    end
  245.   return
  246.       
  247. /*----------------------------- End REXX Source -----------------------------*/
  248.